help.bash

#!/bin/bash

help_all(){
    # do_help $1 0 "Print this help message. \n    Passing a bad function name will also print this help message" || return;
    # do_help $1 0 "Print this help message." || return;
    


    # LIST=`declare -F | awk '{print $NF}' | sort | egrep -v "^_"`
    # FUNCTIONS=($(echo $LIST | tr " " " "))

    local help_messages;
    i=0;

    for f in "${FUNCTIONS[@]}"; do
        if [[ $f == 'do_help' ]]; then
            continue
        fi
        
        response=$($f help);
        # Consider splitting string on the colon (:) instead of assuming sort value is only one character
        sort=${response:0:1};
        response=${response:2};
        help_messages[$i]="$sort:$f:$response";
        i=$(($i+1));
    done
    IFS=$'\n' sorted=($(sort <<<"${help_messages[*]}"))
    

    echo ""
    # echo "                                    WELCOME";
    big_header "                    ----------Let's Git Bent----------";
    # echo "                      -------------------------------------";
    # echo "---- This will help you manage your project versions and backups through git ----"
    # echo "               ---- Commands you need to know are listed below. ----"
    echo "             Just type a command (below), like \`bent newProject\` "
    # command (like \`bent newProject\`) ----"
    # echo "Git Bent: To help you manage your project versions and backups."
    # echo "How To: Type \`bent command\`. The commands you can run are all listed below. "

	
	n="$(color_li 1)"
    d="$(color_li 0)"
    f="${cOff}"
    mod=0
    
    echo ""
    lastSort=0;
    
    for f in "${sorted[@]}"; do
        # format sort_number:func_name:help message
        # get sort number
        # if sort number is larger than last sort number, print new line or divider
        # get func name
        # get help message
        # print format as belo
        # echo "    - bent ${name}: $message"
        # PARTS=($(echo ${f} | tr ":" " "))
        # sort=${PARTS[0]}
        # func=${PARTS[1]}
        # help=${PARTS[2]}
        # out=${f/[0-9]*\:/}
        # func=${f/\:[a-zA-Z]\:/}
        
        sort=$(echo "${f}" | sed 's/:.*//')

        if [[ $sort -ne $lastSort ]]; then
            lastSort=$sort
            echo ""
            # echo "----------"
            # echo ""
            # echo ""
        fi

        rmSort=$(echo "${f}" | sed 's/^[0-9]*://')
        func=$(echo "${rmSort}" | sed 's/:.*//')
        help=$(echo "${rmSort}" | sed 's/[^:]*://')

        func=$(echo "${func}" | sed 's/_/ /')
        # func=${f/*:*:/}
        
        if [[ $mod == 0 ]];then
        	mod=1
	        msg "${d}- [bent ${func}]:${cOff} ${help}";
	    else
	    	mod=0
	        msg "${n}- [bent ${func}]:${cOff} ${help}";
        fi
		
        # echo ""
        # echo "    - ${sort} ________ ${func} :: ${help}";
    done

    echo ""
    echo ""
}